# $Id: PKGBUILD 89938 2013-05-05 21:31:15Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Krzysztof Raczkowski <raczkow@gmail.com>

pkgname=open-vm-tools-modules
epoch=1
pkgver=9.2.3
_pkgsubver=1031360
pkgrel=1
pkgdesc="kernel modules for the open source implementation of VMware Tools"
arch=('i686' 'x86_64')
url="http://open-vm-tools.sourceforge.net/"
license=('GPL')
makedepends=('libdnet' 'procps' 'icu' 'uriparser' 'linux-headers')
depends=('linux')
install=$pkgname.install
options=('!strip' '!makeflags')
source=("http://downloads.sourceforge.net/open-vm-tools/open-vm-tools-$pkgver-${_pkgsubver}.tar.gz"
	"modprobe.conf")
md5sums=('71a1d8065b632692af2cdcc9d82f305e'
         'bc5518489077e91655489bd04b868584')

build() {
  _kernver=$(pacman -Q linux | cut -d . -f 2 | cut -f 1 -d -)
  KERNEL_RELEASE=$(cat /usr/lib/modules/extramodules-3.${_kernver}-ARCH/version)

  cd "$srcdir/open-vm-tools-${pkgver}-${_pkgsubver}"

  sed -i 's|proc-3.2.8|procps|g' configure
  sed -i 's|putname(name);|__putname(name);|' modules/linux/vmblock/linux/control.c

  [ $NOEXTRACT -eq 1 ] || ./configure \
      --prefix=/usr \
      --without-x \
      --with-linuxdir=/usr/lib/modules/$KERNEL_RELEASE

  make -C modules modules
}

package() {
  _kernver=$(pacman -Q linux | cut -d . -f 2 | cut -f 1 -d -)
  depends=("linux>=3.${_kernver}" "linux<3.$(expr ${_kernver} + 1)")
  KERNEL_VERSION=$(cat /usr/lib/modules/extramodules-3.${_kernver}-ARCH/version)
  msg "Kernel = $KERNEL_VERSION"

  cd "$srcdir/open-vm-tools-${pkgver}-${_pkgsubver}"
  mkdir -p $pkgdir/usr/lib/modules/extramodules-3.${_kernver}-ARCH/

  find -type f -name '*.ko' \
    -exec install -t "$pkgdir/usr/lib/modules/extramodules-3.$_kernver-ARCH" {} +

  gzip "$pkgdir/usr/lib/modules/extramodules-3.$_kernver-ARCH"/*.ko

  install -D -m 644 ${srcdir}/modprobe.conf ${pkgdir}/usr/lib/modprobe.d/${pkgname}.conf
  sed -i "s|extramodules-.*-ARCH|extramodules-3.${_kernver}-ARCH|" $startdir/$pkgname.install
}
